package com.shameit.goodqrinfomanager.ui.activity.chuku;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.widget.Adapter;
import android.widget.ArrayAdapter;

import com.chad.library.BR;
import com.shameit.goodqrinfomanager.AppViewModelFactory;
import com.shameit.goodqrinfomanager.BaseMVVMActivity;
import com.shameit.goodqrinfomanager.R;
import com.shameit.goodqrinfomanager.adapter.ChukuAdapter;
import com.shameit.goodqrinfomanager.bean.litepal.RuKu;
import com.shameit.goodqrinfomanager.databinding.ActivityChukuBinding;
import com.shameit.goodqrinfomanager.ui.activity.cangku.CangkuManagementViewModel;

import java.util.List;

public class ChukuActivity extends BaseMVVMActivity<ActivityChukuBinding,ChukuViewModel> {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setToolBarBack(binding.toolbar);
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_chuku;
    }

    @Override
    public int initVariableId() {
        return BR.data;
    }

    @Override
    public ChukuViewModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(ChukuViewModel.class);
    }

    @Override
    protected String setTitle() {
        return "入库管理";
    }

    @Override
    protected void initView() {
        binding.chukuList.setLayoutManager(new LinearLayoutManager(this));
        binding.chukuList.setAdapter(viewModel.adapter = new ChukuAdapter(R.layout.activity_chuku_item));
        binding.chukuList.setScrollBarDefaultDelayBeforeFade(0);
        binding.chukuList.setScrollBarFadeDuration(0);
    }

    @Override
    protected void loadData() {
        String cangwei = getIntent().getStringExtra("cangwei");
        if (!cangwei.isEmpty()) {
            viewModel.cwbh.set(cangwei);
            List<RuKu> list = viewModel.getXiangma(cangwei);
            viewModel.adapter.setNewInstance(list);
            binding.chukuList.scrollToPosition(viewModel.adapter.getItemCount()-1);
        }
    }
}